1. Field of the Invention
The present invention relates to an improved data processing system and, in particular, to a method and apparatus for optimizing performance in a data processing system. Still more particularly, the present invention provides a method and apparatus for enhancing performance of a software program through performance instrumentation.
2. Description of Related Art
Effective management and enhancement of data processing systems requires knowing how and when various system components are operating. In analyzing and enhancing performance of a data processing system and the applications executing within the data processing system, it is helpful to gather information about a data processing system as it is operating.
By instrumenting an application, trace information can be gathered for an application while it is executing. For example, an instrumented application may log every entry and corresponding exit into and from a module, subroutine, method, function, or system component within the executing application. Typically, a time-stamped record is produced for each such event. Corresponding pairs of records similar to entry-exit records may also be used to trace execution of arbitrary code segments, the commencement and completion of I/O or data transmission, and for many other events of interest. Output from instrumentation code may be analyzed in many ways to identify a variety of performance metrics with respect to the execution environment.
However, instrumenting an application to enable collection of trace data may undesirably disturb the execution of the application. After performance measurement instrumentation is added to a program, as the application executes, the instrumentation code may cause significant overhead, such as system calls to obtain a current timestamp or other execution state information.
In order to minimize the undesired effects of instrumentation, the execution of instrumentation code is limited in some manner. Typically, the performance instrumentation is toggled on or off through the use of one or more globally addressable variables that bracket sections of instrumentation code within the instrumented application. As performance instrumentation code is encountered, the global variable is tested to determine whether or not the instrumentation code should be executed. However, even when the instrumentation is turned off, the overhead of testing a global variable may add unacceptable delay to the performance of the application; the execution of the instructions for testing a global variable not only consumes CPU time but may cause the flushing of the instruction cache or instruction pipeline within the processor. Hence, production software is generally shipped without any installed performance instrumentation, and when a performance problem arises at a later time, a version of the production software that contains performance. instrumentation must be built and installed before performance problems can be diagnosed, which is a cumbersome and time-consuming process.
Therefore, it would be advantageous to provide a method and system for eliminating overhead effects of performance instrumentation when the execution of the instrumentation code is unnecessary. It would be particularly advantageous to provide a methodology that allows the performance instrumentation to be present within production-quality software.
The present invention is a method, system, apparatus, or computer program product for minimizing overhead that may be incurred by executing specialized code, such as debug code or instrumentation code for monitoring the performance of the application, that is present within an application. The application executes on a data processing system having a processor containing predicate registers. The application is compiled in a manner in which the processor instructions for the specialized code are predicated using a set of one or more predicate registers that are dedicated or reserved by software convention for predicating the specialized code. In other words, for a given application, compilers and other sources of machine instructions do not generate any predicated processor instructions, other than processor instructions for the specialized code, which use the reserved predicate registers. When the application executes, neither the operating system nor other applications use the reserved predicate registers. An operating system function can be called or invoked to set the values of the reserved predicate registers so that the specialized code either does or does not execute in a chosen manner. Alternatively, the processor contains a set of special predicate registers that are reserved for predicating instrumentation code rather than protecting a set of predicate registers through software convention.